<script setup>
import { useRouter } from "vue-router";
const router = useRouter();

function goForgot() {
  router.push("/forgot");
}
function goRegister() {
  router.push("/register");
}

import { inject } from "vue";
const $message = inject("globalMessage");

import { useUserStore } from "@/stores/user";
const userStore = useUserStore();

import { ref } from "vue";
let account = ref("");
let password = ref("");

function login() {
  if (!account.value && !password.value) {
    $message.error("请输入账号密码");
    return;
  }
  if (!account.value) {
    $message.error("账号不能为空");
    return;
  }
  if (!password.value) {
    $message.error("密码不能为空");
    return;
  }
  userStore.token = "F111111";
  router.push("/home");
}
</script>

<template>
  <div class="bg-purple">
    <div class="stars">
      <div class="central-body">
        <div style="width: 60%">
          <a-divider orientation="left" class="central-title">Login</a-divider>
        </div>
        <a-input
          v-model:value="account"
          class="m-medium-v"
          placeholder="请输入账号"
        ></a-input>
        <a-input-password
          v-model:value="password"
          placeholder="请输入密码"
        ></a-input-password>
        <div class="link-container m-base-v">
          <a-button type="link" @click="goForgot">忘记密码</a-button>
          <a-button type="link" @click="goRegister">没有账号?立即注册</a-button>
        </div>
        <div>
          <a-button type="primary" @click="login">登 录</a-button>
        </div>
      </div>
      <div class="objects">
        <img
          class="object_rocket"
          src="@/assets/imgs/404/rocket.svg"
          width="40px"
        />
        <div class="planet-container">
          <img
            class="object_earth"
            src="@/assets/imgs/404/earth.svg"
            width="650px"
          />
          <img
            class="object_moon"
            src="@/assets/imgs/404/moon.svg"
            width="100px"
          />
          <img
            class="object_astronaut"
            src="@/assets/imgs/404/astronaut.svg"
            width="150px"
          />
        </div>
      </div>
      <div class="glowing_stars">
        <div class="star"></div>
        <div class="star"></div>
        <div class="star"></div>
        <div class="star"></div>
        <div class="star"></div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.bg-purple {
  position: relative;
  user-select: none;
  height: 100vh;
  max-height: 100vh;
  background: url("@/assets/imgs/404/bg_purple.png");
  background-repeat: repeat-x;
  background-size: cover;
  background-position: left top;
  overflow: hidden;
  .stars {
    height: 100%;
    background: url("@/assets/imgs/404/overlay_stars.svg");
    background-repeat: repeat;
    background-size: contain;
    background-position: left top;
    .central-body {
      position: absolute;
      top: 40%;
      left: 75%;
      transform: translate(-50%, -50%);
      padding: 0 20px 20px;
      border-radius: 12px;
      background-color: #f2f2f2;
      text-align: center;
      width: 320px;
      z-index: 100;
      .central-title {
        font-size: 28px;
        font-weight: 700;
        color: @text-color;
        border-color: @text-color;
        margin-bottom: 0;
        :deep(.ant-divider-inner-text) {
          padding: 0 12px;
        }
      }
      .link-container {
        .flex-between();
      }
    }
    .objects {
      img {
        z-index: 90;
      }
      .object_rocket {
        z-index: 95;
        position: absolute;
        transform: translateX(-50px);
        top: 75%;
        pointer-events: none;
        animation: rocket-movement 200s linear infinite both running;
      }
      .planet-container {
        position: absolute;
        top: 80%;
        left: 30%;
        transform: translate(-50%, -50%);
        height: 900px;
        width: 900px;
        .object_earth {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          z-index: 90;
        }
        .object_moon {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          z-index: 95;
          animation: revolution 30s linear infinite;
        }
        .object_astronaut {
          z-index: 88;
          position: absolute;
          top: 22%;
          left: 45%;
          transform: translate(-50%, -50%);
          rotate: 30deg;
        }
      }
    }
    .glowing_stars {
      .star {
        position: absolute;
        border-radius: 100%;
        background-color: #fff;
        width: 5px;
        height: 5px;
        opacity: 0.3;
        will-change: opacity;
        &:nth-child(1) {
          top: 25%;
          left: 80%;
          animation: glow-star 2s infinite ease-in-out alternate 1s;
        }
        &:nth-child(2) {
          top: 20%;
          left: 40%;
          animation: glow-star 2s infinite ease-in-out alternate 3s;
        }
        &:nth-child(3) {
          top: 25%;
          left: 15%;
          animation: glow-star 2s infinite ease-in-out alternate 5s;
        }
        &:nth-child(4) {
          top: 75%;
          left: 80%;
          animation: glow-star 2s infinite ease-in-out alternate 7s;
        }
        &:nth-child(5) {
          top: 90%;
          left: 50%;
          animation: glow-star 2s infinite ease-in-out alternate 9s;
        }
      }
    }
  }
}

@media (max-width: 768px) {
  .central-body {
    top: 50% !important;
    left: 50% !important;
  }
  .planet-container {
    top: 60% !important;
    left: 50% !important;
  }
}

// 公转
@-moz-keyframes revolution {
  from {
    -moz-transform: rotate(0deg) translateX(-500px) rotate(0deg);
  }
  to {
    -moz-transform: rotate(360deg) translateX(-500px) rotate(360deg);
  }
}
@-webkit-keyframes revolution {
  from {
    -webkit-transform: rotate(0deg) translateX(-500px) rotate(0deg);
  }
  to {
    -webkit-transform: rotate(360deg) translateX(-500px) rotate(360deg);
  }
}
@keyframes revolution {
  from {
    transform: rotate(0deg) translateX(-500px) rotate(0deg);
  }
  to {
    transform: rotate(360deg) translateX(-500px) rotate(360deg);
  }
}

@-moz-keyframes rocket-movement {
  100% {
    -moz-transform: translate(1200px, -600px);
  }
}
@-webkit-keyframes rocket-movement {
  100% {
    -webkit-transform: translate(1200px, -600px);
  }
}
@keyframes rocket-movement {
  100% {
    transform: translate(1200px, -600px);
  }
}

@-moz-keyframes glow-star {
  40% {
    -moz-opacity: 0.3;
  }
  90%,
  100% {
    -moz-opacity: 1;
    -moz-transform: scale(1.2);
  }
}
@-webkit-keyframes glow-star {
  40% {
    -webkit-opacity: 0.3;
  }
  90%,
  100% {
    -webkit-opacity: 1;
    -webkit-transform: scale(1.2);
  }
}
@keyframes glow-star {
  40% {
    -webkit-opacity: 0.3;
    opacity: 0.3;
  }
  90%,
  100% {
    -webkit-opacity: 1;
    opacity: 1;
    transform: scale(1.2);
    border-radius: 999999px;
  }
}
</style>
